
import 'package:flutter/material.dart';
import 'package:flutter/cupertino.dart';
import 'package:flutter_swiper/flutter_swiper.dart';
import 'package:cached_network_image/cached_network_image.dart';
import '../player/player.dart';
import 'package:flutter_plugin/flutter_plugin.dart';
class Carousel extends StatefulWidget {
  final List Imgs;
  final Radius borderRadius;

  Carousel({Key key, this.Imgs, this.borderRadius}) : assert(Imgs != null);

  @override
  State createState() => new CarouselState();
}

class CarouselState extends State<Carousel> {
  int pageIndex = 0;
  List listImg = [];



  @override
  void initState() {
    // TODO: implement initState
    super.initState();
    listImg = widget.Imgs;
  }

  @override
  void dispose() {
    // TODO: implement dispose
    super.dispose();
  }

  Widget buildBanner(){

  }
  @override
  Widget build(BuildContext context) {
    return new Swiper(
      itemBuilder: (BuildContext context, int index) {

        return new InkWell(
          child: new Material(
            borderRadius: BorderRadius.all(Radius.circular(10.0)),
            child:new Stack(
              fit:StackFit.passthrough,
              children: <Widget>[
                Image.network(
                  listImg[index]['image'],
                  fit: BoxFit.fill,
                ),
                new Positioned(
                  bottom: 0.0,
                  left: 0.0,
                  right: 0.0,
                  child:  new Container(
                    height: 30.0,
                    child:new Container(
                      alignment: Alignment.centerLeft,
                      height: 30.0,
                      margin: EdgeInsets.only(left: 10.0),
                      child: Text(listImg[index]['title'],style: new TextStyle(color: Colors.white),),
                    ),
                    decoration: new BoxDecoration(
                        color: Colors.black.withOpacity(.5)
                    ),
                  ),
                )
              ],
            )
          ),
          onTap: (){
            if(int.parse(listImg[index]['url'])==0){
              FlutterPlugin.href("com.eg.android.AlipayGphone");
            }else{
              Navigator.of(context).push(
                  new CupertinoPageRoute(builder: (context)=>new PlayerPage(mid:int.parse(listImg[index]['url'])))
              );
            }

          },
        );
      },
      viewportFraction: 0.8,
      scale: 0.9,
      itemCount: listImg.length,
      pagination: new SwiperPagination(
          alignment:Alignment.bottomRight,
        margin: const EdgeInsets.only(right: 50.0,bottom: 7.0),
      ),
      autoplay: true,
    );
  }
}
